package org.celery.modules.other.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.celery.modules.other.entity.LogisticsFee;
import org.celery.modules.other.vo.LogisticsFeeVO;
import org.celery.modules.other.wrapper.LogisticsFeeWrapper;
import org.celery.modules.other.service.ILogisticsFeeService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 * 物流费用表 控制器
 *
 * @author Celery
 * @since 2022-04-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("celery-other/logistics-fee")
@Api(value = "物流费用表", tags = "物流费用表接口")
public class LogisticsFeeController extends BladeController {

	private final ILogisticsFeeService logisticsFeeService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入logisticsFee")
	public R<LogisticsFeeVO> detail(LogisticsFee logisticsFee) {
		LogisticsFee detail = logisticsFeeService.getOne(Condition.getQueryWrapper(logisticsFee));
		return R.data(LogisticsFeeWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 物流费用表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入logisticsFee")
	public R<IPage<LogisticsFeeVO>> list(LogisticsFee logisticsFee, Query query, BladeUser bladeUser) {
		QueryWrapper<LogisticsFee> queryWrapper = Condition.getQueryWrapper(logisticsFee);
		queryWrapper.lambda().orderByDesc(LogisticsFee::getWeight);
		queryWrapper.lambda().eq(LogisticsFee::getTenantId, bladeUser.getTenantId());

		IPage<LogisticsFee> pages = logisticsFeeService.page(
				Condition.getPage(query),
				queryWrapper
		);
		return R.data(LogisticsFeeWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页 物流费用表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入logisticsFee")
	public R<IPage<LogisticsFeeVO>> page(LogisticsFeeVO logisticsFee, Query query) {
		IPage<LogisticsFeeVO> pages = logisticsFeeService.selectLogisticsFeePage(Condition.getPage(query), logisticsFee);
		return R.data(pages);
	}

	/**
	 * 新增 物流费用表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入logisticsFee")
	public R save(@Valid @RequestBody LogisticsFee logisticsFee) {
		return R.status(logisticsFeeService.save(logisticsFee));
	}

	/**
	 * 修改 物流费用表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入logisticsFee")
	public R update(@Valid @RequestBody LogisticsFee logisticsFee) {
		return R.status(logisticsFeeService.updateById(logisticsFee));
	}

	/**
	 * 新增或修改 物流费用表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入logisticsFee")
	public R submit(@Valid @RequestBody LogisticsFee logisticsFee, BladeUser bladeUser) {
		logisticsFee.setTenantId(bladeUser.getTenantId());
		return R.status(logisticsFeeService.saveOrUpdate(logisticsFee));
	}

	
	/**
	 * 删除 物流费用表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(logisticsFeeService.deleteLogic(Func.toLongList(ids)));
	}

	
}
